/**
 * @Title: index
 * @Package mall-fe
 * @author Shinelon
 * @date 2017/9/4 15:46
 * @version V1.0
 */
'use strict';
require('./index.css');

var shiqla=require('util/shiqlamall');
//通用页面头
var header = {
    init:function () {
        this.bindEvent();
    },
    onload:function () {
        var keyword = shiqla.getUrlParam('keyword');
        if(keyword){
            $('#search-input').val(keyword);
        }
    },
    bindEvent:function () {
        var _this = this;
        $('#search-btn').click(function () {
            _this.searchSubmit();
        });
        //按下回车也是搜索提交
        $('#search-input').keydown(function (e) {
            //13 是回车键
            if(e.which === 13){
                _this.searchSubmit();
            }
        });
    },
    searchSubmit:function () {
        var keyword = $.trim($('#search-input').val());
        if(keyword){
            window.location.href='./list.html?keyword=' + keyword;
        }else{
            shiqla.goHome();
        }
    }
};

header.init();